package com.ds.infrastructure.hyperspace.console.schedule;

import com.ds.infrastructure.hyperspace.console.common.methodlock.MethodLockException;
import com.ds.infrastructure.hyperspace.console.common.methodlock.MethodLockId;
import com.ds.infrastructure.hyperspace.console.service.inf.IMetricsManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author: yaozhendong
 * @create: 2019-11-04 11:19
 **/
@Slf4j
@Component
public class MetricsJob {
    @Autowired
    IMetricsManageService metricsManageService;

    /**
     * 执行周期：每一分钟执行一次
     * 进行数据的抓取与聚合
     */
    @Scheduled(cron = "0 0/1 * * * ? ")
    public void doWork() {
        log.info("执行一次节点指标数据抓取。");
        try {
            metricsManageService.crawlMetricsJobWithMethodLockId(MethodLockId.newId("CrawlMetricsJob"));
        } catch (MethodLockException methodLockException) {
            if (!methodLockException.getDuplicateKeyException()) {
                log.error("MetricsJob error：", methodLockException);
            }
        }
    }
}
